package com.hex.liyue.usermodule.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hex.liyue.R;
import com.hex.liyue.commonmodule.fragment.BaseFragment;
import com.hex.liyue.commonmodule.view.DelayButton;
import com.hex.liyue.usermodule.presenter.ForgetPwdPresenter;
import com.hex.liyue.usermodule.presenter.IForgetPwdView;

import butterknife.Bind;
import butterknife.OnClick;


/**
 * 这是一个忘记密码的界面
 * Created by yukoyuan on 16/6/14.
 */
public class ForgetPwdFragment extends BaseFragment implements IForgetPwdView, DelayButton.OnDelayListener {
    @Bind(R.id.et_fg_pwd_phone)
    EditText etFgPwdPhone;
    @Bind(R.id.et_fg_pwd_vcode)
    EditText etFgPwdVcode;
    @Bind(R.id.db_fg_pwd_getvcode)
    DelayButton dbFgPwdGetvcode;
    @Bind(R.id.et_login_pwd)
    EditText etLoginPwd;
    @Bind(R.id.iv_toobar_back)
    ImageView ivToobarBack;
    @Bind(R.id.tv_toobar_title)
    TextView tvToobarTitle;
    private ForgetPwdPresenter forgetPwdPresenter;

    @Override
    public void initdata(Bundle arguments) {
        dbFgPwdGetvcode.setDelayListener(this);
    }

    @Override
    public int getContentLayout() {
        return R.layout.fragment_forget_pwd;
    }

    @Override
    protected void bindPresenter() {
        forgetPwdPresenter = new ForgetPwdPresenter(this);
    }

    @Override
    protected void initToolbar() {
        ivToobarBack.setVisibility(View.VISIBLE);
        tvToobarTitle.setVisibility(View.VISIBLE);
        tvToobarTitle.setText("忘记密码");
    }


    @OnClick({R.id.db_fg_pwd_getvcode, R.id.bt_reset_pwd, R.id.iv_toobar_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.db_fg_pwd_getvcode:
                forgetPwdPresenter.getvcode();
                break;
            case R.id.bt_reset_pwd:
                forgetPwdPresenter.resetPwd();
                break;
            case R.id.iv_toobar_back:
                startLoginFragment();
                break;
        }
    }

    @Override
    public String getPhone() {
        return etFgPwdPhone.getText().toString().trim();
    }

    @Override
    public String getVcode() {
        return etFgPwdVcode.getText().toString().trim();
    }

    @Override
    public String getPwd() {
        return etLoginPwd.getText().toString().trim();
    }

    @Override
    public void showLod(String msg) {
        showLoad(getActivity(), msg);
    }

    @Override
    public void closeLod() {
        closeLoad();
    }

    @Override
    public void showT(String msg) {
        showToast(getActivity(), msg);
    }

    @Override
    public void startLoginFragment() {
        getActivity().onBackPressed();
    }

    @Override
    public void delyTime(int time) {
        dbFgPwdGetvcode.delay(time);
    }

    @Override
    public void onStartDelay(int second) {
        dbFgPwdGetvcode.setEnabled(false);
    }

    @Override
    public void onRun(int second) {

    }

    @Override
    public void onFinish() {
        if (dbFgPwdGetvcode != null) {
            dbFgPwdGetvcode.setEnabled(true);
        }
    }
}